package com.springcloud.market.pay.service;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.function.Consumer;

@Slf4j
@Service
public class UserRegisterMessageHandler {
    /**
     * 处理用户注册事件-赠送积分
     * @return
     */
    @Bean
    public Consumer<java.util.Map<String, Object>> userRegisterConsumer() {
        return message -> {
            String userId = (String) message.get("userId");
            String username = (String) message.get("username");
            log.info("收到用户注册消息，开始处理积分赠送，用户ID: {}, 用户名: {}", userId, username);
            // 这里实现你的积分赠送业务逻辑
            try {
                // pointsService.addWelcomePoints(userId);
                log.info("已为用户 {} 赠送注册积分", userId);
            } catch (Exception e) {
                log.error("赠送积分失败，用户ID: {}", userId, e);
            }
        };
    }
}
